package com.lm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lm.mapper.DocterMapper;
import com.lm.mapper.ResidentMapper;
import com.lm.pojo.Docter;
import com.lm.pojo.LoginBean;
import com.lm.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @version 1.0
 * @dscription:TODO
 * @author32477
 * @date 2025/9/26 16:01
 */
@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    DocterMapper docterMapper;
    @Autowired
    ResidentMapper residentMapper;

    @Override
    public HashMap<String, Object> docterLogin(LoginBean loginBean) {
        String msg = "";
        HashMap<String,Object> map = new HashMap<>();
        QueryWrapper<Docter> queryWrapper = new QueryWrapper<>();
        //验证管理员身份
        queryWrapper.eq("docter_role_id",loginBean.getType());
        queryWrapper.eq("docter_phone",loginBean.getDocterPhone());
        Docter docter = docterMapper.selectOne(queryWrapper);
        if(docter == null){
            msg = "该用户不是管理员";
        }else {
            //验证手机号
            queryWrapper.eq("docter_phone",loginBean.getDocterPhone());
            Docter docter1 = docterMapper.selectOne(queryWrapper);
            if(docter1 == null){
                msg = "手机号不存在";
                map.put("msg",msg);
                return map;
            }else{

                queryWrapper.eq("docter_password",loginBean.getDocterPassword());
                Docter docter2 = docterMapper.selectOne(queryWrapper);
                if(docter2 == null){
                    msg = "密码错误";
                }else{
                    msg = "登录成功";
                    map.put("docter",docter2);
                }

            }
        }

        map.put("msg",msg);
        return map;
    }
}
